define pxe_sl55_64($datapath, $url, $domainname) {

  class pxe_tftp_server {
    tftp { tftpsrv:
      datapath=>$datapath,
    }
  }

  exec { cp_syslinux:
    command => "cp /usr/lib/syslinux/{pxelinux.0,menu.c32,memdisk,mboot.c32,chain.c32} $datapath",
    creates => "$datapath/pxelinux.0",
    require => [Class["pxe_tftp_server"],Package["syslinux"]],
  }

  exec { mkdirpxelinuxcfg:
    command => "mkdir $datapath/pxelinux.cfg",
    creates => "$datapath/pxelinux.cfg",
    require => Class["pxe_tftp_server"],
  }

  exec { mkdirimages:
    command => "mkdir $datapath/images",
    creates => "$datapath/images",
    require => Class["pxe_tftp_server"],
  }

  exec { getvmlinuz:
    command => "wget -O $datapath/images/vmlinuz ftp://ftp.scientificlinux.org/linux/scientific/55/x86_64/images/pxeboot/vmlinuz",
    creates => "$datapath/images/vmlinuz",
    require => [Package["wget"],Exec["mkdirimages"]],
  }
  
  exec { getinitrd:
    command => "wget -O $datapath/images/initrd.img ftp://ftp.scientificlinux.org/linux/scientific/55/x86_64/images/pxeboot/initrd.img",
    creates => "$datapath/images/initrd.img",
    require => [Package["wget"],Exec["mkdirimages"]],
  }
  
  package { ["syslinux","wget"]:
    ensure => installed,
  }
  
  file { "pxe_sl55_defaultconf":
    path => "$datapath/pxelinux.cfg/default",
    owner => root,
    group => root,
    mode => 644,
    content => template("pxe/default.erb"),
    ensure => present,
    require => Exec["mkdirpxelinuxcfg"]
  }
  
  include pxe_tftp_server

  dhcpd {pxe_dhcp_server:
    require=>Class["pxe_tftp_server"],
    interface=>"eth1",
    subnet=>"192.168.100.0",
    netmask=>"255.255.255.0",
    router=>"192.168.100.1",
    domainname=>$domainname,
    dns=>"192.168.100.1",
    range=>"192.168.100.200 192.168.100.254",
    nextserver=>"192.168.100.1",
  }
}

define dhcpd($interface,$subnet,$netmask,$router,$domainname, $dns, $range, $nextserver) {
  
  package{'dhcp':
    ensure => present,
  }
  
  service{'dhcpd':
    ensure => running,
    enable => true,
    hasstatus => true,
    require => [ Package[dhcp], File['/etc/dhcpd.conf', '/etc/sysconfig/dhcpd'] ],
  }
  
  file{'/etc/dhcpd.conf':
    content => template("pxe/dhcpd.conf.erb"),
    require => Package[dhcp],
    notify => Service['dhcpd'],
    owner => root, group => 0, mode => '0644';
  }

  file{'/etc/sysconfig/dhcpd':
    content => template("pxe/dhcpd.erb"),
    require => Package[dhcp],
    notify => Service['dhcpd'],
    owner => root, group => 0, mode => '0644';
  }

}


define tftp($datapath, $disable="no") {

  exec { create_tftp_dir:
    command => "mkdir -p $datapath",
    creates => "$datapath",
  }
            
  package { "tftp-server":
    ensure => installed,
  }
  
  file { "tftp":
    path => "/etc/xinetd.d/tftp",
    owner => root,
    group => root,
    mode => 644,
    content => template("pxe/tftp.erb"),
    ensure => present,
    require => Package["tftp-server"],
    notify => Service["xinetd"]
  }
  
  service { "xinetd":
    ensure => "running",
    hasstatus => "false",
    hasrestart => "false",
    require => [File["tftp"],Package["tftp-server"], Exec["create_tftp_dir"]],
  }
}
